package com.genghis.ptas.study.dao.impl;

import com.genghis.core.page.dao.PageDao;
import com.genghis.ptas.study.dao.StudyRecordDao;
import com.genghis.ptas.study.entity.StudyRecord;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: gaoyang
 * To change this template use File | Settings | File Templates.
 */
@Repository("studyRecordDao")
public class StudyRecordDaoImpl extends PageDao implements StudyRecordDao {

    @Override
    public void addStudyRecord(StudyRecord studyRecord) {
        String sql = "INSERT INTO study_record (id, user_id, study_date, study_record, course_id, category) \n" +
                " VALUES(:id, :userId, :studyDate, :studyRecord, :courseId, :category)";
        getNamedParameterJdbcTemplate().update(sql, new BeanPropertySqlParameterSource(studyRecord));
    }

    @Override
    public List<StudyRecord> findStudyRecordList(StudyRecord studyRecord) {
        String sql = "SELECT * FROM `study_record` WHERE `user_id`= ?";
        return getJdbcTemplate().query(sql, new BeanPropertyRowMapper<StudyRecord>(StudyRecord.class), studyRecord.getUserId());
    }
}
